<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ExtPackage
 *
 * @author gevik
 */
abstract class ExtPackage
{
    private $resourcePath = null;
    private $_controller = null;
    public static $packageName;

    protected abstract function getRoot();
    protected abstract function getImports();
    public abstract function getName();

    public static function getVersion()
    {
        throw new Exception('getVersion not implemented this package');
    }
    
    public function setController($controller)
    {
        $this->_controller = $controller;
    }

    public function addUxScript($fname)
    {
        $this->_controller->addUxScript(array('sm'=>true,'file'=>$this->resourcePath .'/'.$fname));
    }

    public function addUxCss($fname)
    {
        $this->_controller->addUxCss(array('sm'=>true,'file'=>$this->resourcePath .'/'.$fname,'media'=>null));
    }

    public function publishResources()
    {
        $resources = Yii::getPathOfAlias($this->getName() . '.web.resources');
        if (file_exists($resources))
            $this->resourcePath = Yii::app()->getAssetManager()->publish($resources);
    }

    public function init()
    {
        Yii::setPathOfAlias($this->getName(), $this->getRoot());
        $imports = $this->getImports();

        foreach ($imports as $path)
            Yii::import($this->getName() . '.' . $path);
    }
}

?>
